<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>demo15-指令-基础</title>
</head>
<script src="../libs/vue.js"></script>
<style>
    .container{
        width: 100%;
        min-width: 320px;
        max-width: 640px;

        margin:0 auto;
    }
</style>
<body> 
    <div id="app">
        <div>
            <span>页面加载完成后，input 触发focus 自定义指令</span><hr><br>
            <input id="myInputId" v-my-focus type="text" >测试聚焦
        </div>
    </div>
</body>

<script>

Vue.directive('my-focus',{
    /**
     * inserted 与 bind 的不同：
     * console.log(ipt == el )  结果：
     *  inserted为true，bind为false 。可见bind做了不少工作
     */ 
    // 当被绑定的元素插入到 DOM 中时……
    inserted:function(el , binding, vnode , oldVnode){
        var ipt = document.getElementById('myInputId');
        console.log(el);
        console.log(ipt);
        console.log(ipt == el );

        el.focus();

        console.log('binding: ',binding);
        console.log('vnode : ',vnode);
        console.log('oldVnode: ',oldVnode);
    }
})

var app = new Vue({
  el: '#app'
});
</script>
</html>